import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.api.customization.huangwm.dao.SW003.AssetInfoOperationDao;
import com.api.customization.huangwm.formmode.SW003.AssetInfoOperation;
import com.customization.huangwm.utils.HttpRequest;
import weaver.general.GCONST;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author Huangwm
 * @Date 2022-06-01
 * @Version 1.0
 * @Description TODO
 **/
public class ApiRequestTemple {
    private static String url = "http://39.98.117.174";

    public static void main(String[] args) throws Exception {
        //save();
        //update();
        //status();
        //purchaseStorage();
        //purchaseStorageReturn();

        String rootPath = "E:\\WEAVER9\\ecology\\";
        GCONST.setRootPath(rootPath);
        GCONST.setServerName("ecology");
        updateInventory();

//        AssetInfoOperationDao dao = new AssetInfoOperationDao();
//        List<Map<String, String>> datas = new ArrayList<>();
//        Map<String, String> data = new HashMap<>();
//        data.put("assetCode", "huangwm0926");
//        data.put("assetName", "物料名称");
//        data.put("assetDescribe", "物料描述");
//        data.put("unit", "09");
//        data.put("manageDep", "");
//        data.put("assetModel", "型号");
//        data.put("assetType", "AA");
//        data.put("isAsset", "Y");
//        data.put("quantity", "1");
//        data.put("locationCode", "地点编码");
//        data.put("brand", "品牌");
//        data.put("manufacturer", "生产商");
//        data.put("FACode", "FA编码");
//        data.put("prjNo", "项目编码");
//        data.put("price", "100.00");
//        data.put("arrivalDate", "2022-06-01");
//        data.put("supplier", "供应商");
//        datas.add(data);

//        Map<String,Object> params = new HashMap<>();
//        params.put("datas", datas);
//        params.put("poNo", "huangwm0926001");
//        params.put("prid", "20220926");
//        System.err.println( dao.PurchaseStorage(params));
    }

    /**
     * 新增物料
     * @return
     */
    private static Map<String, Object> save() {
        HttpRequest httpRequest = new HttpRequest();
        JSONObject params = new JSONObject();
        List<Map<String, String>> datas = new ArrayList<>();
        Map<String, String> data = new HashMap<>();
        data.put("assetCode", "huangwm0926");
        data.put("assetName", "物料名称");
        data.put("assetDescribe", "物料描述");
        data.put("unit", "09");
        data.put("manageDep", "");
        data.put("assetModel", "型号");
        data.put("assetType", "AA");
        data.put("isAsset", "Y");
        data.put("totalQuantity", "10");
        data.put("usedQuantity", "0");
        data.put("InventoryQuantity", "10");
        datas.add(data);
        params.put("datas", datas);
        try {
            String json = httpRequest.postData(url + "/api/customization/SW003/assetOperation/save", params);
            System.err.println(json);
            return (Map<String, Object>) JSONObject.parse(json);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new HashMap<>();
    }

    /**
     * 更新物料
     * @return
     */
    private static Map<String, Object> update() {
        HttpRequest httpRequest = new HttpRequest();
        JSONObject params = new JSONObject();
        List<Map<String, String>> datas = new ArrayList<>();
        Map<String, String> data = new HashMap<>();
        data.put("assetCode", "itcode001");
        data.put("assetName", "物料名称");
        data.put("assetDescribe", "物料描述");
        data.put("unit", "09");
        data.put("assetModel", "型号");
        data.put("assetType", "AA");
        datas.add(data);
        params.put("datas", datas);
        try {
            String json = httpRequest.postData(url + "/api/customization/SW003/assetOperation/update", params);
            System.err.println(json);
            return (Map<String, Object>) JSONObject.parse(json);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new HashMap<>();
    }

    /**
     * 封存、解封物料
     * @return
     */
    private static Map<String, Object> status() {
        HttpRequest httpRequest = new HttpRequest();
        JSONObject params = new JSONObject();
        Map<String, String> data = new HashMap<>();
        data.put("assetCode", "itcode001");
        data.put("action", "sealed");
        params.put("datas", data);
        try {
            String json = httpRequest.postData(url + "/api/customization/SW003/assetOperation/status", params);
            System.err.println(json);
            return (Map<String, Object>) JSONObject.parse(json);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new HashMap<>();
    }

    /**
     * 采购入库
     * @return
     */
    private static Map<String, Object> purchaseStorage() {
        HttpRequest httpRequest = new HttpRequest();
        JSONObject params = new JSONObject();
        List<Map<String, String>> datas = new ArrayList<>();
        Map<String, String> data = new HashMap<>();
        data.put("assetCode", "huangwm0926");
        data.put("assetName", "物料名称");
        data.put("assetDescribe", "物料描述");
        data.put("unit", "09");
        data.put("manageDep", "");
        data.put("assetModel", "型号");
        data.put("assetType", "AA");
        data.put("isAsset", "Y");
        data.put("quantity", "1");
        data.put("locationCode", "地点编码");
        data.put("brand", "品牌");
        data.put("manufacturer", "生产商");
        data.put("FACode", "FA编码");
        data.put("prjNo", "项目编码");
        data.put("price", "100.00");
        data.put("arrivalDate", "2022-06-01");
        data.put("supplier", "供应商");
        datas.add(data);
        params.put("datas", datas);
        params.put("poNo", "PO单编号");
        System.err.println(params);
        try {
            String json = httpRequest.postData(url + "/api/customization/SW003/assetOperation/purchaseStorage", params);
            System.err.println(json);
            return (Map<String, Object>) JSONObject.parse(json);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new HashMap<>();
    }

    /**
     * 采购退货
     *
     * @return
     */
    private static Map<String, Object> purchaseStorageReturn() {
        HttpRequest httpRequest = new HttpRequest();
        JSONObject params = new JSONObject();
        List<Map<String, String>> datas = new ArrayList<>();
        Map<String, String> data = new HashMap<>();
        data.put("assetCode", "huangwm0926");
        data.put("poNo", "PO单编号");
        data.put("quantity", "5");
        datas.add(data);
        params.put("datas", datas);
        try {
            String json = httpRequest.postData(url + "/api/customization/SW003/assetOperation/purchaseStorageReturn", params);
            System.err.println(json);
            return (Map<String, Object>) JSONObject.parse(json);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new HashMap<>();
    }

    /**
     * 出入库
     *
     * @return
     */
    private static Map<String, Object> updateInventory() {
        HttpRequest httpRequest = new HttpRequest();
        JSONObject params = new JSONObject();
        JSONArray array = new JSONArray();
        Map<String, String> into1 = new HashMap<>();
        into1.put("action", "into");
        into1.put("assetCode", "itcode001");
        into1.put("quantity", "-1");
        into1.put("requestNumber", "出库单编号");
        into1.put("reason", "说明原因");
        array.add(into1);
        Map<String, String> into2 = new HashMap<>();
        into2.put("action", "into");
        into2.put("assetCode", "itcode002");
        into2.put("quantity", "1");
        into2.put("requestNumber", "入库单编号");
        into2.put("reason", "说明原因");
        array.add(into2);
        params.put("datas", array);
        try {
            AssetInfoOperationDao api = new AssetInfoOperationDao();
            System.err.println(api.UpdateInventoryV2(params));
//            String json = httpRequest.postData(url + "/api/customization/SW003/assetOperation/updateInventory", params);
//            System.err.println(json);
//            return (Map<String, Object>) JSONObject.parse(json);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new HashMap<>();
    }
}
